package com.example.thread.base.demo3;

import lombok.extern.slf4j.Slf4j;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/12/14 21:58
 */
@Slf4j
public class Demo3 {
    public static void main(String[] args)  throws Exception{
        Thread thread=new Thread(new StopThread());
        thread.start();
        Thread.sleep(5);
        thread.interrupt();
    }
}

/**
 * interrupt 标记位 停止线程
 */
class StopThread extends Thread{
    @Override
    public void run(){
        int count=0;
        int countLimit=1000;
        while (!Thread.currentThread().isInterrupted() && count < countLimit){
            System.out.println("nowCount:"+count++);;
        }
    }
}
